#pragma once
#include <iostream>
#include <string>
#include <cstdio>
#include <pthread.h>
using namespace std;

typedef void*(*func_t)(void*);
class threaddata
{
public:
    string _name;
    void* _args;
};
class thread
{
public:
    thread(func_t callback,int num,void* args)
    :_callback(callback)
    ,_tid(0)
    {
        char namebuffer[64];
        snprintf(namebuffer,sizeof(namebuffer),"thread-%d",num);
        _name = namebuffer;
        _td._args = args;
        _td._name = _name;
    }
    void start()//创建线程
    {
        pthread_create(&_tid,nullptr,_callback,(void*)&_td);
    }
    void join()
    {
        pthread_join(_tid,nullptr);
    }
	string getname()
	{
		return _name;
	}
    ~thread()
    {}
private:
    string _name;
    func_t _callback;
    pthread_t _tid;
    threaddata _td;
};
